package cn.zn.framework.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageInUtils<T> {
    private Long offset = 0L;
    private Long limit = 10L;
    private String search;
    private String order;
    private T entity;

    public IPage<T> getPageObj() {
        //分页参数
        long curPage = this.getPage();

        return new Page<>(curPage, this.limit);
    }

    public Long getPage() {
        long curPage = 1;
        if (this.getOffset() != null) {
            curPage = this.getOffset() / this.limit + 1;
        }
        return curPage;
    }
}
